package com.bbzn.user.client.service.impl;

import com.bbzn.user.client.constant.RedisConstant;
import com.bbzn.user.client.service.CommonService;
import com.bbzn.user.client.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author wulongbo
 * @Date 2021/3/18 15:22
 * @Version 1.0
 */

@Service
public class CommonServiceImpl implements CommonService {

    @Autowired
    private RedisUtils<String> redisUtil;

    @Override
    public String getWebSalt(HttpServletRequest request) {
        String token = request.getHeader(RedisConstant.HEADER).replace(RedisConstant.PREFIX + " ", "");
        String id = redisUtil.get(token);
        return redisUtil.get(RedisConstant.PREFIX_WEB + id);
    }

    @Override
    public String getAppSalt(HttpServletRequest request) {
        String token = request.getHeader(RedisConstant.HEADER).replace(RedisConstant.PREFIX + " ", "");
        String id = redisUtil.get(token);
        return redisUtil.get(RedisConstant.PREFIX_APP + id);
    }

    @Override
    public Long getUserId(HttpServletRequest request) {
        String token = request.getHeader(RedisConstant.HEADER).replace(RedisConstant.PREFIX + " ", "");
        return Long.valueOf(redisUtil.get(token));
    }

}
